package com.culturalCenter.dataCenter.service.impl.activity;

import com.culturalCenter.dataCenter.customEntity.responseParam.activity.ActivityResourceResponse;
import com.culturalCenter.dataCenter.entity.activity.ActivityResource;
import com.culturalCenter.dataCenter.entity.activity.ActivityResourceCount;
import com.culturalCenter.dataCenter.mapper.activity.ActivityResourceCountMapper;
import com.culturalCenter.dataCenter.mapper.activity.ActivityResourceMapper;
import com.culturalCenter.dataCenter.service.activity.ActivityResourceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author zhao
 * @Date 2020/11/5 14:22
 */
@Service
public class ActivityResourceServiceImpl implements ActivityResourceService {

    @Resource
    private ActivityResourceMapper activityResourceMapper;
    @Resource
    private ActivityResourceCountMapper activityResourceCountMapper;

    @Override
    public ActivityResourceResponse getPictureAndVideo(String activityId, int pageNum, int pageSize) {
        ActivityResourceResponse activityResourceResponse = new ActivityResourceResponse();
        PageHelper.startPage(pageNum, pageSize);
        // 图片视频列表
        List<ActivityResource> activityResourceList = activityResourceMapper.queryPictureAndVideo(activityId);
        PageInfo<ActivityResource> pageInfo = new PageInfo<>(activityResourceList);
        activityResourceResponse.setResourceList(pageInfo);
        // 图片视频所占比例
        List<ActivityResourceCount> activityResourceCountList = activityResourceCountMapper.queryResourceRatioByActivityId(activityId);
        if (CollectionUtils.isNotEmpty(activityResourceCountList)) {
            activityResourceResponse.setResourceRatio(activityResourceCountList);
        }

        return activityResourceResponse;
    }

}
